package com.atguigu.guli.api.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;


import org.springframework.web.cors.CorsConfiguration;

import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;


@Component
public class GlobalGatewayConfig {
    @Bean
    public CorsWebFilter corsWebFilter() {
        UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource() ;
        //配置跨域设置
        CorsConfiguration corsConfiguration = new CorsConfiguration() ;
        corsConfiguration.addAllowedHeader("*");//允许携带哪些请求头跨域访问
        corsConfiguration.addAllowedOrigin("*");//允许携带哪些组织跨域访问
        corsConfiguration.addAllowedMethod("*");//允许哪些请求方式跨域访问
        corsConfiguration.setAllowCredentials(true); //允许携带cookie
        configurationSource.registerCorsConfiguration("/**",corsConfiguration);//所有接口都可以被跨域访问
        return new CorsWebFilter(configurationSource) ;
    }
}
